const Koa = require('koa')
const app = new Koa()

const browser = require('child_process')
const PORT = 2333

const views = require('koa-views')
const {
  resolve
} = require('path')
const {
  connect
} = require('./database/init')

;
(async () => {
  await connect()
})()


app.use(views(resolve(__dirname, './views'), {
  extension: 'pug'
}))

app.use(async (ctx, next) => {
  await ctx.render('index', {
    you: 'koa-views',
    me: 'pug'
  })
})

app.listen(PORT)

console.log('koa2 is starting at port ' + PORT)
browser.exec('start http://127.0.0.1:' + PORT)